/**
 * HTTP路由处理类
 * 模块:Portal
 * @param {Object} app
 * @param {Object} jsonFileService
 */
module.exports = function(app,jsonFileService) {
   
	//配置API路由,地址和对应的回调函数，通过回调响应请求发送数据
    app.get ('/api/new/getMenu',sysmenu);
    app.post('/api/new/2',setting);
    
    
    //*******************************************************
    //处理HTTP的回调函数
    //数据文件的目录
    var datapath = '/data/portal/';
    
    //GET /api/portal/sysmenu
    function sysmenu(req, res,next){
    	//JSON文件
    	var fileName = datapath + 'sysmenu.json';
        //发送JSON数据
        res.send(jsonFileService.getJsonFromFile(fileName));
    }
    
    /**
     * POST /api/portal/setting
	 * post: 		{"key":1,"data":"更新数据"}   res:setting.1
	 * post及其它: 	{"key":2,"data":"更新数据"}   res:setting.err01
     */
    function setting(req, res,next){
    	//JSON文件
    	var fileName;
    	
    	var fileName1 = 	'setting.1.json';
    	var fileNameErr01 = 'setting.err01.json';
    	//请求数据
    	var datakey = req.body.key;
    	console.log('datakey:' + datakey);
		switch (datakey){
		    case 1:
		        fileName = fileName1;
		        break;
		    case 2:
		    case 3:
		        fileName = fileNameErr01;
		        break;
		    default:
		        fileName = fileNameErr01;
		        break;
		}
		
		fileName = datapath + fileName;
        //发送JSON数据
        res.send(jsonFileService.getJsonFromFile(fileName));
    }
};